package com.zs.studentmanager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zs.studentmanager.entity.domain.Role;
import com.zs.studentmanager.entity.vo.PageVo;
import com.zs.studentmanager.service.RoleService;
import com.zs.studentmanager.mapper.RoleMapper;
import org.springframework.stereotype.Service;

/**
* @author 周小白。
* @description 针对表【s_role(系统角色信息表)】的数据库操作Service实现
* @createDate 2024-01-19 19:58:37
*/
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role>
    implements RoleService{

    private final RoleMapper roleMapper;

    public RoleServiceImpl(RoleMapper roleMapper) {
        this.roleMapper = roleMapper;
    }


    /**
     * 获取角色列表
     * @param pageNum 页码
     * @param pageSize 每页数量
     * @param searchValue 搜索值
     * @return 角色列表
     */
    @Override
    public PageVo<Role> getPageList(Integer pageNum, Integer pageSize, String searchValue) {
        Page<Role> page = new Page<>(pageNum, pageSize);

        LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(Role::getName, searchValue);

        // 查询
        Page<Role> rolePage = roleMapper.selectPage(page, queryWrapper);

        PageVo<Role> pageVo = new PageVo<>();
        pageVo.setTotal(rolePage.getTotal());
        pageVo.setList(rolePage.getRecords());
        pageVo.setPages(rolePage.getPages());

        return pageVo;
    }
}




